
// Copyright (C) 2007 Richard Uhler
// This file is part of Esiply.
//
// Esiply is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License, Version 2,
// as published by the Free Software Foundation.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.

#ifndef _COMPLETION_H_
#define _COMPLETION_H_

// A Completion is the touple (type, value, target)
// type is one of normal, break, continue, return, throw.
// value is some javascript value.
// target is an identifier.
//
// This is a type that the javascript programmer has no access
// to. So we'll call it a pseudotype, like Reference and List.
//
// Where Ecma refers to an 'empty' value, we will use Null::null, just
// by convention. This should be fixed eventually, because that's not
// really the right way to do it.
//
// Where Ecma refers to an empty target, we use the object provided
// by Completion::empty.

#include "Value.h"
#include "ValueType.h"

enum CompletionType
{
    CT_NORMAL,
    CT_BREAK,
    CT_CONTINUE,
    CT_RETURN,
    CT_THROW,
};

class Completion : public Value
{
public:
    Completion(CompletionType type, Value* value, String* target);
    virtual ValueType getType() const;

    virtual Value* getValue();
    virtual bool isException() const;

    CompletionType type() const;
    Value* value() const;
    String* target() const;

    // The value to use for an empty target.
    static String* empty;

private:
    CompletionType m_type;
    Value* m_value;
    String* m_target;
};

#endif//_COMPLETION_H_

